Handle rufus_scheduler v3 also

Stop rufus_scheduler v3 leaking ActiveRecord handles. See [this StackOverflow answer for details](http://stackoverflow.com/a/19380690/1270789).

rufus_scheduler v3 [deprecated `start_new`](https://github.com/jmettraux/rufus-scheduler/blob/master/lib/rufus/scheduler.rb#L120), so instead I call `new`. In [v2.0.22 this creates a `PlainScheduler`](https://github.com/jmettraux/rufus-scheduler/blob/82b70feeb28b2aa778d1d869aba12b580966a786/lib/rufus/scheduler.rb#L33), but fortunately the defaults that Huginn uses means that `start_new` in v2.0.22 also creates a `PlainScheduler`.

KenYN 11 years ago
parent
commit
9991825d56
1 changed files with 12 additions and 8 deletions
  1. 12 8
      bin/schedule.rb

+ 12 - 8
bin/schedule.rb

@@ -11,22 +11,26 @@ end
11 11
 require 'rufus/scheduler'
12 12
 
13 13
 def run_schedule(time, mutex)
14
-  mutex.synchronize do
15
-    puts "Queuing schedule for #{time}"
16
-    Agent.delay.run_schedule(time)
14
+  ActiveRecord::Base.connection_pool.with_connection do
15
+    mutex.synchronize do
16
+      puts "Queuing schedule for #{time}"
17
+      Agent.delay.run_schedule(time)
18
+    end
17 19
   end
18 20
 end
19 21
 
20 22
 def propogate!(mutex)
21
-  mutex.synchronize do
22
-    puts "Queuing event propagation"
23
-    Agent.delay.receive!
23
+  ActiveRecord::Base.connection_pool.with_connection do
24
+    mutex.synchronize do
25
+      puts "Queuing event propagation"
26
+      Agent.delay.receive!
27
+    end
24 28
   end
25 29
 end
26 30
 
27 31
 mutex = Mutex.new
28 32
 
29
-scheduler = Rufus::Scheduler.start_new
33
+scheduler = Rufus::Scheduler.new
30 34
 
31 35
 # Schedule event propagation.
32 36
 
@@ -59,4 +63,4 @@ end
59 63
   end
60 64
 end
61 65
 
62
-scheduler.join
66
+scheduler.join